const loginCheck = require('../controller/user')
const { SuccessModel, ErrorModel } = require('../module/resModel')
const userRouter = (req, res) => {
  //根据不通的路由匹配对应的controller层
  const path = req.path
  const method = req.method
  res.setHeader('Content-Type', 'application/json')

  // 注意📢 method 大小写
  if (path === '/api/user/login' && method === 'POST') {
    const { userName, password } = req.body
    if (!userName || !password) {
      return new ErrorModel('用户名或密码不能为空')
    } else return new SuccessModel(loginCheck(userName, password))
  } else return false
}

module.exports = userRouter
